home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 12 - 1996 / 12.06 Jun 96 / 12.06 Symantec Top 10 < prev    next >
Encoding:
Text File  |  1996-05-10  |  4.4 KB  |  112 lines  |  [TEXT/R*ch]

  1.  
  2.  
  3. A:    Yes.  There is a struct element called the rgnBBox that can be accessed by
  4. type-casting the WindowPtr to a WindowPeek.  The following example demonstrates
  5. how to access this data:
  6.  
  7.     WindowPtr    myWindow;                    // must point to valid window
  8.     RgnHandle    windowRgnHandl;            // local copy of handle
  9.     Rect        totalWindRect;            // receives total area of window
  10.  
  11.     // set up the handle to the structRgn
  12.     windowRgnHandle =
  13.         (Handle)(((WindowPeek)theWindow)->structRgn);
  14.     // lock the handle since we are ready to access it
  15.     HLock(windowRgnHandle);
  16.     // get the rectangle for the entire window
  17.     totalWindRect = (**(RgnHandle)windowRgnHandle).rgnBBox;
  18.     // unlock the handle, we are done with it
  19.     HUnlock( windowRgnHandle );
  20.  
  21. Q:    I am using the Think Class Library and Visual Architect to create a dialog
  22. box.  When I run the generated application, I notice that the tab order for the
  23. CDialogText items is not correct.  Is there any way to change the tab order
  24. without re-creating my dialog box?
  25.  
  26. A:    Yes.  Tab order is determined by the item numbers of the text boxes.  For
  27. example, if you have three text items numbered 2, 7, and 3, pressing Tab in the
  28. first edit box (number 2) will cause the cursor to jump to the last edit box
  29. (number 3).  To display the item numbers, choose Show Item Numbers from the
  30. Views menu.  You can change the tab order of CDialogText items in Visual
  31. Architect by selecting each item individually and choosing Send To Back and
  32. Bring To Front from the Pane menu.  Bring To Front will increase the item number
  33. and Send To Back decreases the item number.
  34.  
  35. Q:    When I click in the go-away (close) box in my VA-generated CWindow, I do
  36. not receive a cmdClose message like I do when I use the Menu option Close or hit
  37. -W.  Why does the close box not generate a cmdClose that I can trap, and how
  38. can I override this mysterious TCL shortcut?
  39.  
  40. A:    The window’s close box circumvents the cmdClose command path that is
  41. normally issued after the Close menu option is chosen.  The close box issues a
  42. CWindow::UserClose() command, which calls CWindow::Close(), which finally calls
  43. CDirector::Close(), at which point your close click disappears into the
  44. forbidding domain of CDirector, having completely circumvented the command
  45. structure of the TCL.
  46.  
  47.     Overriding this is fairly straightforward.  In the Visual Architect, create
  48. a new class in the Classes dialog window.  Call it what you like; TmyWindow
  49. would be a good choice.  Select CWindow from the Base Class popup menu, and
  50. close the Classes dialogue window.  From the main VA window, open your window,
  51. or create one if you do not already have one.  Select View Info from the View
  52. menu.  Now select your newly created derived class from the Window Class pop-up
  53. menu.
  54.     Once you generate your source code, you need to add a prototype in your
  55. header file and then go into the source file for your derived class and add the
  56. following:
  57.  
  58. void    TmyWindow::Close()
  59. {
  60.     // Add your own supplementary Close handling routines here
  61.  
  62.     inherited::Close();    // Call the inherited method 
  63.                                 // to finally close the window
  64. }
  65.  
  66.     Now when the close box is clicked, your Close method will get called,
  67. wherein you can add whatever housekeeping functionality you like.
  68.  
  69. Q:    I am using TCL and the Visual Architect to write my application.  I have
  70. created a modal dialog box with a button that sends a cmdQuit.  When I run the
  71. generated application, clicking the button seems to do nothing.  In fact, I seem
  72. to go into some kind of infinite loop and I have to force my application to
  73. quit.  What is going on?
  74.  
  75. A:    First of all, it is considered bad form to quit an application by clicking
  76. a button.  That behavior is reserved for the Quit item in the File menu.  If,
  77. for some reason, you really want this behavior, you will need to do the
  78. following.
  79.  
  80.     Go into your upper level source for that dialog, and add the following class
  81. definition:
  82.  
  83. class myChore: public CChore
  84. {    
  85.     public:
  86.         myChore(){}
  87.         virtual void Perform( long *maxSleep )
  88.             {gApplication->Quit();}
  89. };
  90.  
  91.     Now, modify the DoCommand function:
  92.  
  93. myDialog::DoCommand( long theCommand )
  94. {
  95.         myChore *theChore = new myChore();
  96.  
  97.         switch ( theCommand )
  98.         {
  99.             case cmdQuit:
  100.                 Close( true );                                    
  101.                 gApplication->AssignIdleChore( theChore );
  102.                 break;
  103.             default:
  104.                 x_myDialog::DoCommand( theCommand );
  105.         }
  106. }
  107.  
  108.     By setting up an idle chore, we ensure that the dialog has a chance to close
  109. before the application quits.
  110.  
  111. Special thanks to: Mark Baldwin, Levi Brown, Andrew McFarland, and Scott Morison.
  112.